#!/usr/bin/env bash

if [ ! -d "$HOME/data" ]; then
    mkdir -p "$HOME/data"
fi
curl -o ~/data/nextcloud-29.0.3.tar.bz2 https://download.nextcloud.com/server/releases/nextcloud-29.0.3.tar.bz2
tar -xjvf ~/data/nextcloud-29.0.3.tar.bz2
sudo apt update
sudo apt install \
    --no-install-recommends \
    --yes \
    caddy php php-fpm php-curl php-gd php-mbstring php-pgsql php-sqlite3 php-xmlwriter php-zip
sudo cp -r ~/data/nextcloud/ /var/www/
sudo chown -R www-data:www-data /var/www/nextcloud
cat << EOF >> /etc/caddy/Caddyfile

:4780 {
	# Set this path to your site's directory.
	root * /var/www/nextcloud

	# Enable the static file server.
	file_server

	# Or serve a PHP site through php-fpm:
	php_fastcgi unix//run/php/php8.2-fpm.sock
}
EOF
